//
//  DDChargeViewPhoneViewController.m
//  DingDongZP
//
//  Created by weily on 16/5/12.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDChargeViewPhoneViewController.h"
#import "DDMeCell.h"
#import "DDInfoInputCell.h"

@interface DDChargeViewPhoneViewController ()
<UITableViewDataSource,
UITableViewDelegate>
{
    NSArray *_titleArray;
    NSString *_faceValue;
    NSArray *_faceValueArray;
}
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSString *faceValue;

@end

@implementation DDChargeViewPhoneViewController

- (instancetype)init {
    self = [super init];
    if (self) {
        _titleArray = @[@"面值", @"卡号", @"卡密"];
        _faceValueArray = @[@"30", @"50", @"100", @"200"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"话费充值卡";
    self.view.backgroundColor = COLOR_BACKGROUND;
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.tableFooterView = [self footView];
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.tableView = tableView;
    
    [tableView registerNib:[UINib nibWithNibName:@"DDInfoInputCell" bundle:nil] forCellReuseIdentifier:@"input"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - tableview
#pragma mark - table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        static NSString *CustomCellIdentifier = @"DDMeCell";
        
        DDMeCell *cell = (DDMeCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"DDMeCell" owner:self options:nil] lastObject];
        }
        
        cell.titleLabel.text = _titleArray[indexPath.row];
        cell.subTitleLabel.text = self.faceValue;
        
        return cell;
    }
    else
    {
        DDInfoInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"input"];
        
        cell.titleLabel.text = _titleArray[indexPath.row];
        
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        UIActionSheet *act = [[UIActionSheet alloc] initWithTitle:@"面值" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil];
        for (NSString *face in _faceValueArray) {
            [act addButtonWithTitle:[NSString stringWithFormat:@"%@元",face]];
        }
        [act showInView:self.view];
        
        ///	事件
        NSArray *faces = _faceValueArray;
        __weak typeof(self) weakSelf = self;
        [act bk_setDidDismissBlock:^(UIActionSheet *act, NSInteger idx)
        {
            weakSelf.faceValue = faces[idx-1];
            [weakSelf.tableView reloadData];
        }];
    }
}

- (UIView *)footView
{
    UIView *foot = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 200)];
    
    UIButton *charge = [[UIButton alloc] initWithFrame:CGRectMake(20, 10, self.view.width-40, 35)];
    [charge setBackgroundColor:COLOR_FONT_MAIN_GREEN];
    charge.layer.cornerRadius = 4.;
    charge.layer.masksToBounds = YES;
    
//    __weak typeof(self) weakSelf = self;
    [charge bk_addEventHandler:^(id sender) {
        ///	点击充值事件
        
    } forControlEvents:UIControlEventTouchUpInside];
    
    [foot addSubview:charge];
    
    return foot;
}

@end
